package hongcaosp.app.android.user.settings.safety.update.presenter;

import android.text.TextUtils;

import hongcaosp.app.android.login.UserToken;
import hongcaosp.app.android.modle.BaseResponse;
import hongcaosp.app.android.modle.DataCallBack;
import hongcaosp.app.android.modle.impl.PasswordModleImpl;
import hongcaosp.app.android.user.settings.safety.update.iview.UpdateByPasswordIView;
import xlj.lib.android.base.component.BasePresenter;
import xlj.lib.android.base.toastcompat.ToastManager;

public class UpdateByPasswordPresenter extends BasePresenter {

    private UpdateByPasswordIView iView;
    private PasswordModleImpl passwordModle;

    public UpdateByPasswordPresenter(UpdateByPasswordIView iView) {
        this.iView = iView;
        passwordModle = new PasswordModleImpl();
    }

    public void check(String password) {
        if (TextUtils.isEmpty(password)) {
            ToastManager.getInstance().showToast("请输入现有密码");
            return;
        }
        passwordModle.updatePassWordOld(UserToken.getDefault().getToken(), password, new DataCallBack<BaseResponse>() {
            @Override
            public void onGetData(BaseResponse data) {
                super.onGetData(data);
                iView.checkOver();
            }

            @Override
            public void onFail(int code, String errorMessage) {
                super.onFail(code, errorMessage);
                ToastManager.getInstance().showToast(errorMessage);
            }
        });
    }
}
